/*
 *  Copyright (C) 2011 Sherlock Downloader
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.sherlock.commons.plugins;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;

import org.sherlock.commons.model.RemoteFile;
import org.sherlock.commons.plugins.model.Plugin;

/**
 *
 * @author Sherlock Downloader
 */
public abstract class URLRevealer extends Plugin {

    private String domain;
    
    public URLRevealer() {
        super(Plugin.Type.REVEALER);
    }
    
    public String getDomain() {
        return domain;
    }
   
    public abstract ArrayList<RemoteFile> getURLs(URL url) throws RevealerException;
    
    protected String getContent(InputStream stream, Charset charset) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charset));
        StringBuilder buffer = new StringBuilder();
        
        String line = null;
        while ((line = reader.readLine()) != null) {
            buffer.append(line).append("\n");
        }
        stream.close();
        
        return buffer.toString();
    }
    
    public void setDomain(String domain) {
        this.domain = domain;
    }
}